# -*- coding: utf-8 -*-
"""
Created on Thu Apr 23 09:36:20 2020

@author: 付说举于版筑之间
"""
from oD66 import od
import copy
from collections import defaultdict
from pandas.core.frame import DataFrame
pltYs=[]
pltYt=[]
pltDs={}
pltDt={}
seedNum=0
totVeh=6


def judgeEx(a, b):  # a和b是两个字符串，这个方程负责比较两个字符串并返回不是0的那个元素的值（不是位置
    for i in range(len(a)):
        if a[i] != b[i]:
            if a[i] != "0":
                return a[i]
            else:
                return b[i]
            
for _ in range(1000):
    seedNum+=1
    #print('seedNum',seedNum)
    o_d=od(seedNum,totVeh)
    start_list=o_d.getO()
    end_list=o_d.getD()
    end_list=['0','0','0']+end_list+['0','0','0']
    #print('start_list',start_list,'len(start_list)',len(start_list))
    #,'end_list',end_list,'len(end_list)',len(end_list)
    from oneWay66 import oneway
    ini_astar=oneway(len(start_list),start_list,end_list)
    printL,time_consuming=ini_astar.get_results()
    diPoint = []
    listA = []
    s_count = 0
    finalSt = defaultdict(list)
    #print(finalSt.items())
    for i in range(len(printL) - 1):  # 把所有的字符串遍历一下
        listA.append(judgeEx(printL[i].split('.'), printL[i + 1].split('.')))
    #print(listA)
    diPoint.append(listA[0])
    for i in range(0, len(listA)):
        if listA[i] not in diPoint:
            finalSt[s_count].append(printL[i + 1])
            diPoint.append(listA[i])
        else:
            s_count += 1
            finalSt[s_count].append(printL[i + 1])
            diPoint.clear()
            diPoint.append(listA[i])
    #
    steps=len(finalSt.items())
    pltYs.append(steps)
    pltYt.append(time_consuming)
    print('time_consuming',time_consuming,'steps',steps)
    oneway.clear()


pltDs['{} cars'.format(totVeh)]=pltYs
pltYs=[]
pltDt['{} cars'.format(totVeh)]=pltYt
pltYt=[]
astarS=DataFrame(pltDs)
astarT=DataFrame(pltDt)
print('astarS6pyemp',astarS)
print('astarT6pyemp',astarT) 
astarS.to_csv("astarS6pyemp.csv",index=False)
astarT.to_csv("astarT6pyemp.csv",index=False)
